<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/15 0015
 * Time: 13:56
 */

namespace app\admin\controller;


use think\Db;

class Beili extends Middle
{
    //todo 背离列表
    public function BeiliList(){
        $list = Db::name('beili_data')
            ->select();
        return $this->returnSuccess($list);
    }

    //todo 背离参数
    public function BeiliData(){
        $list = Db::name('beili_set')
            ->select();
        return $this->returnSuccess($list);
    }
    //todo 背离参数详情
    public function BeiliDetail(){
        $map = ['id'=>$this->data['id']];
        $ref = Db::name('beili_set')->where($map)->find();
        if(!$ref)return $this->returnError('没有该项参数');
        return $this->returnSuccess($ref);
    }

    //todo 背离参数详情
    public function BeiliSet(){
        $map = ['id'=>$this->data['id']];
        $ref = Db::name('beili_set')->where($map)->find();
        if(!$ref)return $this->returnError('没有该项参数');
        $map['content'] = $this->data['num'];
      	$map['title'] = $this->data['title'];
      	$map['msg'] = $this->data['msg'];
        $res = Db::name('beili_set')->update($map);
        if($res)return $this->returnSuccess(null,'设置成功');
        return $this->returnError($this->Error);
    }

    //todo 时段价格
    public function BeiliPrice(){
        $page = $this->page($this->data);
        $list = Db::name('beili')
            ->order('time desc')
            ->limit($page['page'],$page['limit'])
            ->select();
        if($list){
            foreach ($list as $k=>$v){
                $list[$k]['time'] = date('Y-m-d H时',strtotime($v['time'].'00'));
            }
        }
        $count = Db::name('data')
            ->count();
        return $this->returnSuccess(['list'=>$list,'count'=>$count]);
    }
}